<?php

include_once('../elements/element.class.php');
include_once('../elements/div.class.php');
include_once('../elements/table.class.php');
include_once('../elements/tr.class.php');
include_once('../elements/td.class.php');
include_once('../elements/a.class.php');
include_once('../elements/img.class.php');

/*******************************************************************************
 * 
 * 
 * 
 * 
 ******************************************************************************/


class wToolbar
{
	
	############################################################################
	#
	# PROPERTIES
	#
	############################################################################

	protected $cellWidth = 0;	// width of an array cell containing a picture
	protected $className = '';
	protected $id = '';
	protected $content = '';

	############################################################################
	#
	# CONSTRUCTOR
	#
	############################################################################
	
	public function __construct($buttons=false,$id=false)
	{
		$this->className = strtolower(get_class($this));
		$this->id = ($id && $id != '') ? $id : $this->className;
		
		if ($buttons && !empty($buttons)) $this->cellWidth = 100 / (count($buttons));
		
		$columns = array();
		
		foreach ($buttons as $image => $link)
		{
				$pic = new img($image);
				$pic->setAttribute('class',$this->className);
				print_r($pic);
				$a = new a($pic,$link);
				$a->setAttribute('class',$this->className);
				$td = new td($a);
				$td->setAttribute('width',$this->cellWidth . '%');
				$td->setAttribute('class',$this->className);
				array_push($columns, $td);
		}
		
		$tr = new tr($columns);
		$tr->setAttribute('class',$this->className);
		$table = new table($tr);
		$tableAttributes = array('id' => $this->id . 'table',
								 'class' => $this->className);
		$table->setAttributes($tableAttributes);
		$container = new div($table);
		$container->setAttribute('id',$this->id);
		$this->content = $container->preRender();
	}
	
	public function preRender()
	{
		return $this->content;
	}
	
	public function render()
	{
		print $this->content;
	}
	
}


?>
